from django.core.mail import send_mail

from celery_tasks.celery_main import app
import logging

from jt31 import settings

logger = logging.getLogger(__name__)


@app.task(name ="send_mail_task" )
def send_mail_task(email,html_message):
    """

    :param email:  收件人邮箱
    :param html_message:  邮箱正文内容
    :return:
    """
    try:
        # 邮件操作
        res = send_mail(
            subject = "jutong31系统",
            message = "",
            from_email = settings.EMAIL_HOST_USER,
            recipient_list = [email],
            html_message = html_message
        )

    except Exception as e:
        logger.error(f"邮件发送异常{e}【email:{email}】")
    else:
        # res = 1
        if res :
            logger.info(f"邮件发送成功【email:{email}】")
        else:
            logger.warning(f"邮件发送失败【email:{email}】")